<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="css/mui.min.css" rel="stylesheet" />

		<style>
			ul {
				font-size: 14px;
				color: #8f8f94;
			}
			.mui-btn {
				padding: 10px;
			}
			.bs-alert{
				padding: 10px;
				color:red;
			}
			body,.mui-content{
				background-color: white;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav" style="padding-right: 15px;">
			<h1 class="mui-title">消息中心</h1>
			<button id='setting' class=" mui-pull-right mui-btn-link">设置</button>
		</header>
		<div class="mui-content">
			<div class="mui-content-padded">
				<p>
					登录商家账号(目前仅支持商家，后台管理员暂时不支持)即可绑定当前app作为消息接收端，消息类型有：
					<ol>
						<li>订单消息</li>
						<li>货款消息</li>
						<li>账号消息</li>
						<li>商品消息</li>
						<li>其它消息</li>
					</ol>
				
				</p>
				<button type="button" class="mui-btn mui-btn-green mui-btn-block" id="start-bind">开始绑定</button>
				
				<p class="bs-alert">为了消息及时有效推送，请保持app运行状态，开启允许消息通知权限。没有账号的请先到商家中心注册后使用。</p>
				
			</div>
			<div id="list">
				<ul class="mui-table-view">
				    <li class="mui-table-view-cell" id="to-manager">商家中心 
				        <!-- <span class="mui-badge mui-badge-primary">11</span> -->
				    </li>
				    <li class="mui-table-view-cell" id="to-store" >店铺中心
				        <!-- <span class="mui-badge mui-badge-success">22</span> -->
				    </li>
				    
				</ul>
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/app.js"></script>
		<script>
			(function($, doc) {
				$.init();
				var settings = app.getSettings();
				$.plusReady(function() {
					
					var settingPage = $.preload({
						"id": 'setting',
						"url": 'setting.html'
					});
					
					var bind = doc.getElementById('start-bind');
					
					bind.addEventListener('tap',function(e){
						var token = app.getCache('token_merchant');
						//console.log('token',token)
						if(!token){
							$.openWindow({
								url: 'login.html',
								id: 'login',
								show: {
									aniShow: 'pop-in'
								},
								waiting: {
									autoShow: false
								}
							});
							return ; 
						}
						//绑定个推检查
						app.bind_cid();
						
					});
					
					var tostore = doc.getElementById('to-store');
					var tomanager = doc.getElementById('to-manager');
					//店铺
					tostore.addEventListener('tap',function(e){
						var bsUrls = app.getCache('bsUrls');
						if(bsUrls){
							bsUrls = JSON.parse(bsUrls)
						}
						if(!bsUrls.store){
							$.openWindow({
								url: 'login.html',
								id: 'login',
								show: {
									aniShow: 'pop-in'
								},
								waiting: {
									autoShow: false
								}
							});
						}
						
						$.openWindow({
							url: bsUrls.store,
							show: {
								aniShow: 'pop-in'
							},
							waiting: {
								autoShow: false
							}
						});
					});
					//管理
					tomanager.addEventListener('tap',function(e){
						var bsUrls = app.getCache('bsUrls');
						if(bsUrls){
							bsUrls = JSON.parse(bsUrls)
						}
						if(!bsUrls.manager){
							return mui.alert('您未开通店铺，请登录后台后开通店铺','提示','确定',function (e) {
							   e.index
							},'div')
						}
						
						$.openWindow({
							url: bsUrls.manager,
							show: {
								aniShow: 'pop-in'
							},
							waiting: {
								autoShow: false
							}
						});
					});

					
					// 添加监听从系统消息中心点击消息启动事件
					plus.push.addEventListener('click', function(msg){
						// 分析msg.payload处理业务逻辑 
						/* $.openWindow({
							url: 'manager.html',
							show: {
								aniShow: 'pop-in'
							},
							waiting: {
								autoShow: true
							}
						}); */
						//直接打开商家后台
						mui.openWindow({
							url: 'https://vip.bs.wei1.top/plugin/merchant.order/index.html',
							show: {
								aniShow: 'pop-in'
							},
							waiting: {
								autoShow: false
							}
						});
					}, false);
						
					
					
					//设置
					var settingButton = doc.getElementById('setting');
					//settingButton.style.display = settings.autoLogin ? 'block' : 'none';
					settingButton.addEventListener('tap', function(event) {
						$.openWindow({
							id: 'setting',
							show: {
								aniShow: 'pop-in'
							},
							styles: {
								popGesture: 'hide'
							},
							waiting: {
								autoShow: false
							}
						});
					});
				
					//--
					$.oldBack = mui.back;
					var backButtonPress = 0;
					$.back = function(event) {
						backButtonPress++;
						if (backButtonPress > 1) {
							plus.runtime.quit();
						} else {
							plus.nativeUI.toast('再按一次退出应用');
						}
						setTimeout(function() {
							backButtonPress = 0;
						}, 1000);
						return false;
					};
				});
			}(mui, document));
		</script>
	</body>

</html>